#include<iostream>
#include<algorithm>
using namespace std;

int a[10010] ;
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(;m--;){
		next_permutation(a,a+n);
	}
	for(int i=0;i<n;i++)cout<<a[i]<<" ";
	return 0;
}
